$(function () {
    $.ajax({
        type : 'get', //提交方式
        url : "/selectalldep2", //路径
        //参数
        //返回普通的字符流不要写 dataType : "json"
        success : function(data) {
            console.log(data);
            vm.result=data;
        }
    });
    create_account.initial();
});
var create_account = {

	initial : function initial() {
        $("form.form-horizontal").submit(function () {
            var flag= create_account.verifyInput();
            console.log("提交==="+flag);
            return flag;
        })
	},




	verifyInput : function verifyInput() {
		$(".form-message").empty();
		var result = true;
		var check_u = this.checkUsername();
		var check_t = this.checkTrueName();
		var check_e = this.checkEmail();
		var check_p = this.checkPassword();
		/*var check_pc = this.checkConfirmPassword();*/
		var check_id = this.checkNationalId();
		var check_phone = this.checkPhoneNum();
		/*var check_dep = this.checkDepartment();*/
		console.log("check_u=="+check_u)
		console.log("check_t=="+check_t)
		console.log("check_e=="+check_e)
		console.log("check_p=="+check_p)
		console.log("check_id=="+check_id)
		console.log("check_phone=="+check_phone)
		result = check_u && check_t && check_e && check_p && check_id && check_phone;
		return result;
	},

	checkUsername : function checkUsername() {
		var username = $(".form-userName input").val();
		if (username == "" || username == null) {
			$(".form-userName .form-message").text("用户名不能为空");
			return false;
		} else if (username.length > 20 || username.length < 4) {
			$(".form-userName .form-message").text("请保持在4-20个字符以内");
			return false;
		} else {
			var re = /[\+|\-|\\|\/||&|!|~|@|#|\$|%|\^|\*|\(|\)|=|\?|´|"|<|>|\.|,|:|;|\]|\[|\{|\}|\|]+/;
			if (re.test(username)) {
				$(".form-userName .form-message").text("只能是数字字母或者下划线的组合");
				return false;
			} else
				return true;

		}
		return true;
	},
	checkTrueName : function checkTrueName() {
		var truename = $(".form-true-Name input").val();
		if (truename == ""||truename==null) {
			$(".form-true-Name .form-message").text("真实姓名不能为空");
			return false;
		} else if (truename.length > 20 || truename.length < 2) {
			$(".form-true-Name .form-message").text("请保持在2-20个字符以内");
			return false;
		}
		return true;
	},
	checkEmail : function checkEmail() {
		var email = $(".form-email input").val();
		if (email == ""||email==null) {
			$(".form-email .form-message").text("邮箱不能为空");
			return false;
		} else if (email.length > 60 || email.length < 9) {
			$(".form-email .form-message").text("请保持在9-60个字符以内");
			return false;
		} else {
			var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
			if (re.test(email)) {
				return true;
			} else {
				$(".form-email .form-message").text("无效的邮箱");
				return false;
			}

		}
		return true;
	},

	checkPhoneNum : function checkPhoneNum() {
		var phonenum = $(".form-phoneNum input").val();
		if (phonenum == "" || phonenum==null) {
			$(".form-phoneNum .form-message").text("号码不能为空");
			return false;
		} else {
			var re = /^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/;
			if (!re.test(phonenum)) {
				$(".form-phone .form-message").text("手机不合法");
				return false;
			} else
				return true;

		}
		return true;
	},

	checkPassword : function checkPassword() {
		var password = $(".form-password input").val();
		if (password == ""||password==null) {
			$(".form-password .form-message").text("密码不能为空");
			return false;
		} else if (password.length < 6 || password.length > 20) {
			$(".form-password .form-message").text("密码请保持在6到20个字符以内");
			return false;
		} else {
			return true;
		}
		return true;
	},
	/*checkConfirmPassword : function checkConfirmPassword() {
		var password_confirm = $(".form-password-confirm input").val();
		var password = $(".form-password input").val();
		if (password_confirm == "") {
			$(".form-password-confirm .form-message").text("请再输入一次密码");
			return false;
		} else if (password_confirm.length > 20) {
			$(".form-password-confirm .form-message").text(
					"内容过长，请保持在20个字符以内");
			return false;
		} else if (password_confirm != password) {
			$(".form-password-confirm .form-message").text("2次密码输入不一致");
			return false;
		} else {
			return true;
		}
	},*/
	checkNationalId : function checkNationalId() {
		var idcard = $(".form-national-Id input").val();
		if (idcard == ""||idcard==null) {
			$(".form-national-Id .form-message").text("不能为空");
			return false;
		} else if (idcard.length > 20 || idcard.idcard < 5) {
			$(".form-national-Id .form-message").text("请保持在5-20个字符以内");
			return false;
		} else {
			var re = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
			if (!re.test(idcard)) {
				$(".form-national-Id .form-message").text("身份证信息不合法");
				return false;
			} else
				return true;

		}
		return true;
	}
}; 